package GUI;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JPanel;
import Base.Movie;
import Base.MovieCompilation;
import InOut.LanguageSelectionInOut;

/**
 * This class creates the manipulation buttons. Depending on the system state
 * and selected icon, the corresponding buttons will be shown or hide.
 * @author Wayang Group Bremen
 * @version 0.9
 */
public class ButtonStateGui extends JPanel{

	private static final long serialVersionUID = 1L;
	public JButton text;
	public JButton flip;
	public JButton sound;
	public JButton rotateL;
	public JButton rotateR;
	public JButton delete;
	public JButton hide;
	public JButton unhide;
	public JButton AddElement;
	public LanguageSelectionInOut langReader;
	public MovieCompilation story;

	/**
	 * This method creates buttons with status visible(false)
	 * @param langReader an instance of the language array
	 * @param story the vector containing the movies x
	 */
	public ButtonStateGui(LanguageSelectionInOut langReader,MovieCompilation story) {
		this.langReader = langReader;
		this.story = story;
		//this.AddElement = new JButton((langReader.languageSel("AddElement")),new ImageIcon("Data/icons/image-add-24x24.png"));
		ImageIcon myIcon_add = new ImageIcon("Data/icons/add.png");
		this.AddElement = new ButtonGui(myIcon_add);
		//this.AddElement.setBackground(new Color(0,0,0,0));
		//this.AddElement.setBorder(null);
		this.AddElement.setLocation(529, 88);
		this.AddElement.setSize(45, 45);
		this.AddElement.setVisible(true);
		ImageIcon myIcon_text = new ImageIcon("Data/icons/text.png");
		ImageIcon myIcon_text_over = new ImageIcon("Data/icons/text_over.png");
		this.text = new ButtonGui(myIcon_text);
		this.text.setRolloverIcon(myIcon_text_over);
		//this.text.setBackground(new Color(0,0,0,0));
		//this.text.setBorder(null);
		//this.text.add(new JLabel("text"));
		this.text.setLocation(606, 4);
		this.text.setSize(78, 71);
		this.text.setVisible(false);

		ImageIcon myIcon_flip = new ImageIcon("Data/icons/Flip.png");
		ImageIcon myIcon_flip_over = new ImageIcon("Data/icons/Flip_over.png");
		this.flip = new ButtonGui(myIcon_flip);
		this.flip.setRolloverIcon(myIcon_flip_over);
		//this.flip.add(new JLabel(langReader.languageSel("flip")));
		//this.flip.setBorder(null);
		this.flip.setLocation(731,37);
		this.flip.setSize(96, 96);
		this.flip.setVisible(false);

		ImageIcon myIcon_sound = new ImageIcon("Data/icons/sound.png");
		ImageIcon myIcon_sound_over = new ImageIcon("Data/icons/sound_over.png");
		this.sound = new ButtonGui(myIcon_sound);
		this.sound.setRolloverIcon(myIcon_sound_over);
		//this.sound.add(new JLabel(langReader.languageSel("sound")));
		this.sound.setLocation(653, 54);
		this.sound.setSize(75, 71);
		this.sound.setVisible(false);

		ImageIcon myIcon_RotL = new ImageIcon("Data/icons/RotL.png");
		ImageIcon myIcon_RotL_over = new ImageIcon("Data/icons/RotL_over.png");
		this.rotateL = new ButtonGui(myIcon_RotL);
		this.rotateL.setRolloverIcon(myIcon_RotL_over);
		//this.rotateL.add(new JLabel("rot-L"));
		this.rotateL.setLocation(817, 2);
		this.rotateL.setSize(96, 96);
		this.rotateL.setVisible(false);


		ImageIcon myIcon_RotR = new ImageIcon("Data/icons/RotR.png");
		ImageIcon myIcon_RotR_over = new ImageIcon("Data/icons/RotR_over.png");
		this.rotateR = new ButtonGui(myIcon_RotR);
		this.rotateR.setRolloverIcon(myIcon_RotR_over);
		//this.rotateR.add(new JLabel("rot-R"));
		this.rotateR.setLocation(903, 35);
		this.rotateR.setSize(96, 96);
		this.rotateR.setVisible(false);

		ImageIcon myIcon_delete = new ImageIcon("Data/icons/Del.png");
		this.delete = new ButtonGui(myIcon_delete);
		//this.delete.add(new JLabel(langReader.languageSel("delete")));
		this.delete.setLocation(529, 88);
		this.delete.setSize(45, 45);
		this.delete.setVisible(false);

		//ImageIcon myIcon_hide = new ImageIcon("Data/icons/Hide.png");
		//ImageIcon myIcon_hide_over = new ImageIcon("Data/icons/Unhide.png");
		ImageIcon myIcon_hide = new ImageIcon("Data/icons/Unhide.png");
		ImageIcon myIcon_hide_over = new ImageIcon("Data/icons/Hide.png");
		this.hide = new ButtonGui(myIcon_hide);
		this.hide.setRolloverIcon(myIcon_hide_over);
		//this.hide.add(new JLabel(langReader.languageSel("hide")));
		this.hide.setLocation(550, 40);
		this.hide.setSize(61, 61);
		this.hide.setVisible(false);

		//ImageIcon myIcon_unhide = new ImageIcon("Data/icons/Unhide.png");
		ImageIcon myIcon_unhide = new ImageIcon("Data/icons/Hide.png");

		this.unhide = new ButtonGui(myIcon_unhide);
		this.unhide.setRolloverIcon(myIcon_hide);
		//this.unhide.add(new JLabel(langReader.languageSel("unhide")));
		this.unhide.setLocation(550, 40);
		this.unhide.setSize(61, 61);
		this.unhide.setVisible(false);

		this.text.setToolTipText((langReader.languageSel("tt_text")));
		this.flip.setToolTipText((langReader.languageSel("tt_flip")));
		this.sound.setToolTipText((langReader.languageSel("tt_sound")));
		this.rotateL.setToolTipText((langReader.languageSel("tt_rotL")));
		this.rotateR.setToolTipText((langReader.languageSel("tt_rotR")));
		this.delete.setToolTipText((langReader.languageSel("tt_delete")));
		this.hide.setToolTipText((langReader.languageSel("tt_hide")));
		this.unhide.setToolTipText((langReader.languageSel("tt_unhide")));

		this.AddElement.setToolTipText((langReader.languageSel("tt_Add")));

	}

	/**
	 * This method hides all icons
	 */
	public void hideAllIcons() {
		AddElement.setVisible(false);
		text.setVisible(false);
		flip.setVisible(false);
		sound.setVisible(false);
		rotateL.setVisible(false);
		rotateR.setVisible(false);
		delete.setVisible(false);
		hide.setVisible(false);
		unhide.setVisible(false);
	}

	/**
	 * This method show the add element button if a SceneElement is selected from the list. 
	 */
	public void selFigureInList() {
		hideAllIcons();
		AddElement.setVisible(true);
	}
	/**
	 *  This method hides the add element buttons, after the Element has been added to the editor.
	 */
	public void removeSelFigureInList() {
		hideAllIcons();
		//		AddElement.setVisible(false);
	}

	/**
	 * This method selects the hidden figures in the Character selection window.
	 */
	public void selHiddenFigureInList() {
		hideAllIcons();
		unhide.setVisible(true);
	}

	/**
	 * This method selects a figure in the drawingpanel
	 * @param isRecord indicates if the system is in a record state
	 */
	public void selFigurInEditor(boolean isRecord) {
		hideAllIcons();
		flip.setVisible(true);
		sound.setVisible(true);
		rotateL.setVisible(true);
		rotateR.setVisible(true);
		delete.setVisible(true);
		if(isRecord) {				// if we we are recording, text and hide should be shown
			text.setVisible(true);
			hide.setVisible(true);
		}
		else {						// if not, not
			text.setVisible(false);
			hide.setVisible(false);	
		}
	}
	/**
	 * This method selects a background in the drawingpanel
	 * @param isRecord indicates if the system is in a record state
	 */
	public void selBackgroundInEditor(boolean isRecord) {
		hideAllIcons();
		delete.setVisible(true);
		if(isRecord) {				// if we we are recording, text and hide should be shown
			text.setVisible(true);
			hide.setVisible(true);
		}
		else {						// if not, not
			text.setVisible(false);
			hide.setVisible(false);	
		}
	}

	/**
	 * This method is called each time the stop button is clicked.
	 * If a SceneElement has focus, special methods are called and the available buttons will be displayed.
	 */
	public void stopWasClicked() {
		Movie activeMovie = story.compilation.get(story.activeMovie);
		for(int i =0;i<activeMovie.mv.size();i++) {
			if(activeMovie.mv.get(i).hasFocus) {
				if(activeMovie.mv.get(i).isFigure) {
					selFigurInEditor(false);
				}
				else{
					selBackgroundInEditor(false);	
				}
			}
		}
	}

	/**
	 * This method is called each time the record button is clicked.
	 * If a SceneElememt has focus, special methods are called and the available buttons will be displayed.
	 */
	public void RecordWasClicked() {
		Movie activeMovie = story.compilation.get(story.activeMovie);
		for(int i =0;i<activeMovie.mv.size();i++) {
			if(activeMovie.mv.get(i).hasFocus) {
				if(activeMovie.mv.get(i).isFigure) {
					//System.out.println("focus in rec buttonState: " +activeMovie.mv.get(i).isFigure);
					selFigurInEditor(true);
				}
				else{
					selBackgroundInEditor(true);	
				}
			}
		}
	}  
}
